<template>
<div class="admin">
	<div class="header">
		<h3>欢迎管理员: 
			<span style="color: #DC143C;">{{ $store.state.user.username }}</span>
			进入后台管理系统
		</h3>
	</div>
	<div class="container clearfix">
		<div class="sidebarLeft">
			<ul>
				<router-link tag="li" to="/admin/allUser">allUser</router-link>
				<router-link tag="li" to="/admin/movies">movies</router-link>
				<router-link tag="li" to="/admin/cinemas">cinemas</router-link>
				<router-link tag="li" to="/admin/other">other</router-link>
				<li>users - 1</li>
				<li>movie - 1</li>
				<li>cinema - 1</li>
				<li>other - 1</li>
				<li>users - 2</li>
				<li>movie - 2</li>
				<li>cinema - 2</li>
				<li>other - 2</li>
			</ul>
		</div>
		<div class="main">
            <keep-alive>
			    <router-view/>
            </keep-alive>
		</div>
	</div>
	<div class="footer">@ 后台管理</div>
</div>
</template>

<script>
import axios from "axios";
export default {
	name: "admin",
	// 路由前置守卫     获取用户信息
	beforeRouteEnter(to, from, next) {
        if(!localStorage.getItem("token")) {
            alert("您已退出，请先登录")
            next("/mine/login")
            return;
        }
        if(to.meta.requireAuth && localStorage.getItem("isAdmin")) {
			axios.get("/user/admin").then(res => {
                if (res.data.status === 200) {
                    next();
                } else if(res.data.status === 400) {
                    alert(res.data.code+"， 请及时充值以方便使用更多的权限")
                    next("/mine/center");
                }
            });
        }
    },
};
</script>

<style scoped>
.header,
.container,
.footer {
	margin-left: auto;
	margin-right: auto;
	text-align: center;
}
.header,
.footer {
    width: 100%;
	height: 50px;
	line-height: 50px;
	background: #cad8cb;
}
.header h3{
    overflow: hidden;
    width: calc(100% - 20px);
    padding-left: 10px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.container {
	margin-top: 10px;
    margin-bottom: 10px;
}
.sidebarLeft,
.main {
	font-size: 16px;
	background: #cad8cb;
}
.main {
    padding: 10px;
    box-sizing: border-box;
}
.sidebarLeft li:hover {
    cursor: pointer;
    color: #f05454;
}
.sidebarLeft li.router-link-active {
	color: #C40000;
	font-weight: bolder;
}

/* media   > 538px */
@media screen and (min-width:538px) {
	.header,
	.container,
	.footer {
		width: 100%;
	}
    .container {
        height: 500px;
    }
	.sidebarLeft,
	.main {
        float: left;
		height: 100%;
    }
	.sidebarLeft {
		overflow: hidden;
		overflow-y: scroll;
		width: 160px;
		-webkit-overflow-scrolling: touch;
		scroll-behavior:smooth;
	}
	.sidebarLeft ul li {
		width: 100%;
		line-height: 4;
		background-color: #7ac35f;
		margin-bottom: 10px;
	}
	.sidebarLeft ul li:last-of-type {
		margin-bottom: 0;
	}
	.main {
		margin-left: 10px;
		width: calc(100% - 170px);
	}
}

/* media  < 538px */
@media screen and (max-width:538px) {
	.header,
	.container,
	.footer {
		width: 100%;
    }
    .container {
        height: 500px;
    }
	.sidebarLeft {
		overflow-x: scroll;
		overflow-y: hidden;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		height: 50px;
		white-space: nowrap;
		-webkit-overflow-scrolling: touch;
		scroll-behavior:smooth;
	}
	.sidebarLeft ul li {
		flex-shrink: 0;
		display: inline-block;
		width: 100px;
		height: 30px;
		line-height: 30px;
		border-right: 1px solid #e77e81;
	}
	.sidebarLeft ul li:last-of-type {
		border-right: none;
	}
	.main {
		margin-top: 10px;
		width: 100%;
		height: calc(100% - 60px);
	}
}
</style>
